package com.example.wyc.mybiye1;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Point;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wyc.mybiye.R;
import com.example.wyc.mybiye1.shenYingApi.CurveView;
import com.example.wyc.mybiye1.shenYingApi.LightSensorManager;
import com.example.wyc.mybiye1.shenYingApi.RecordThread;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import WZ_Link.WZ_Link_Inter;

import static android.content.Context.WIFI_SERVICE;

public class Ma2Activity{
    private Activity mContext;
    private LayoutInflater mInflater;
    private View mCurrentView;

    Context context_t;
    //--
    private RecordThread recordThread;
    public LightSensorManager lightSensorManager;
    private CurveView mCurveView;
    private TextView mTextView;
//    private Button mButton;
    private boolean mIsStop = true;
    public Button renLian;
    //--
    public Ma2Activity(Activity context, Context context_t){
        this.mContext=context;
        this.context_t=context_t;
        //为之后将Layout转化为view时用
        mInflater = LayoutInflater.from(mContext);
    }

    public void initView(){
        //设置布局文件
        mCurrentView = mInflater.inflate(R.layout.activity_ma2, null);
        mCurveView =  mCurrentView.findViewById(R.id.curve);
        mTextView = mCurrentView.findViewById(R.id.textView1);
        lightSensorManager = new LightSensorManager(context_t, mHandler);
        renLian=mCurrentView.findViewById(R.id.renLian);
//        mButton =  mCurrentView.findViewById(R.id.button1);
        jianTing();
    }
    public void jianTing(){
                    recordThread = new RecordThread(mHandler);
                    recordThread.startRecord();
                    mCurveView.clearScreen();
//                    mIsStop = false;
//        mButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (mIsStop) {
//                    recordThread = new RecordThread(mHandler);
//                    recordThread.startRecord();
//                    mCurveView.clearScreen();
//                    mButton.setText("停止");
//                    mIsStop = false;
//                } else {
//                    recordThread.stopRecord();
//                    mButton.setText("开始");
//                    mIsStop = true;
//                }
//            }
//        });

        renLian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context_t,Main3Activity.class);
                context_t.startActivity(intent);
            }
        });
    }
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {
                case RecordThread.UPDATE_VIEW:
                    mCurveView.addVisiablePoint(new Point(msg.arg2, msg.arg1));
                    break;
                case LightSensorManager.LIGHT_WHAT:
                    mTextView.setText(String.valueOf(msg.obj));
                    break;
            }
            super.handleMessage(msg);
        }
    };
    public void yanChi(int i){
        try {
            Thread.sleep(i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 获取当前在导航栏上方显示对应的View
     */
    public View getView() {
        if (mCurrentView == null) {
            initView();
        }
        return mCurrentView;
    }
    /**
     * 显示当前导航栏上方所对应的view界面
     */
    public void showView(){
        if(mCurrentView == null){
            initView();
        }
        mCurrentView.setVisibility(View.VISIBLE);
    }

}
